﻿using Harmontronics.DataAccess.IOperate.Business;
using Harmontronics.Model.Common;
using Harmontronics.Model.Dto.Model;
using Harmontronics.Model.Entitys;
using Harmontronics.Repository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Harmontronics.DataAccess.Operate.Business
{
    public class UserRecipeOperate : IUserRecipeOperate
    {
        private HcDbContext _db { get; set; }
        public UserRecipeOperate(HcDbContext db)
        {
            _db = db;
        }
        //查询所有
        public List<UserRecipe> GetAllUserRecipeList()
        {

            return _db.UserRecipes.ToList();
        }

        public List<UserRecipe> GetUserRecipeByRecipeId(string id)
        {
            return _db.UserRecipes.Where(i => i.RecipeId == id).ToList();
        }

        public List<UserRecipe> GetUserRecipeByRecipeIdList(List<string> ids)
        {
            return _db.UserRecipes.Where(i => ids.Contains(i.RecipeId)).ToList();
        }
        public List<UserRecipe> GetUserRecipeByIdList(List<string> recipeIds, List<string> parmaterIds)
        {
            return _db.UserRecipes.Where(i => (recipeIds.Contains(i.RecipeId))&&(parmaterIds.Contains(i.ParameterId))).ToList();
        }

        public void AddUserRecipe(UserRecipe entity)
        {
            _db.UserRecipes.Add(entity);
        }

        public void UpdateUserRecipe(UserRecipe entity)
        {
            _db.UserRecipes.Update(entity);
        }

        public void DeleteUserRecipe(UserRecipe entity)
        {
            _db.UserRecipes.Remove(entity);
        }

        public void BatchDelUserRecipe(List<UserRecipe> entity)
        {
            _db.UserRecipes.RemoveRange(entity);

        }
        public UserRecipe GetUserRecipeByIds(string recipeId, string parmaterId) {
            return _db.UserRecipes.SingleOrDefault(i => (i.RecipeId == recipeId)&&(i.ParameterId == parmaterId));
        }
    }
}
